<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片切换</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
       #outer {
           width: 632px;
           height: 388px;
           margin: 0 auto;
           background-color: skyblue;
           text-align: center;
       }
    </style>
    <script>
        window.onload = function() {
            //点击按钮切换图片
            var prev = document.getElementById("prev");
            var next = document.getElementById("next");
            var img = document.getElementsByTagName("img")[0];
            var imgArr = ["imgs/1.jpg","imgs/2.jpg","imgs/3.jpg"]; 
            var index = 0;
            var info = document.getElementById("info");
            prev.onclick = function() {
                index--;
                if(index < 0){
                    index = imgArr.length-1
                };
                img.src = imgArr[index];
                info.innerHTML="共 "+imgArr.length+" 张,当前第 "+(index+1)+" 张";
            };
            next.onclick = function() {
                index++;
                if(index > imgArr.length-1){
                    index = 0;
                };
                img.src = imgArr[index];
                info.innerHTML="共 "+imgArr.length+" 张,当前第 "+(index+1)+" 张";
            };
            info.innerHTML="共 "+imgArr.length+" 张,当前第 "+(index+1)+" 张";
        };
    </script>
</head>
<body>
    <div id="outer">
        <p id="info"></p>
        <img src="imgs/1.jpg" alt="">
        <button id="prev">上一张</button>
        <button id="next">下一张</button>
    </div>
</body>
</html>